<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>美团外卖</title>
  <!-- 引入 axios -->
  <script src="./js/axios.min.js"></script>
  <!-- 引入 Vue.js -->
  <script src="./js/vue@2.7.14.js"></script>
  <link rel="stylesheet" href="./css/active.css">
</head>
<body>
  <div id="app" v-cloak >
    <div class="banner"><img src="https://tp.juzicps.com/juzicps/images/20230614/1686724718046_16.png"></div>
    <div class="item-list">
      <!-- 添加数据不存在的提示 -->
      <div v-if="!items.length" class="no-data">抱歉，暂无数据</div>
        <div v-for="(item, index) in items" :key="index" class="item">
          <div class="imgbox">
            <img v-if="item.pic" :src="item.pic"  srcset="" width="100%">
			 <img v-else :src="defimg" srcset="" width="100%">
          </div>
          <div class="flex jus padd">
            <div >
              <div>{{ item.name||'--' }}</div>
              <div class="flex">
                <img src='./img/hot.png' height="30">
                <span class="text">劲爆抢购价</span>
                <div class="price-box"> ¥<span class="price" v-text="item.price || '--'"></span></div>
              </div>
            </div>
            <a  class="btn-primary" :href="item.actUrl">立即抢购</a>
          </div>
        </div>
      </div>
  </div>

  <script>
    new Vue({
      el: '#app',
      data: {
        items: [],
		defimg:'https://tp.juzicps.com/juzicps/images/20230614/1686724718046_16.png',
		sid :'517b3e9d14a84d8bab4e70d0314ca295'
      },
      created() {
        const sid = this.getUrlParam('sid') || this.sid;
        this.getData(sid);
      },
      methods: {
        // 获取 URL 参数
        getUrlParam(name) {
          const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
          const r = window.location.search.substr(1).match(reg);
          if (r !== null) {
            return decodeURIComponent(r[2]);
          }
          return '';
        },
        getData(sid) {
          axios({
            //agent/mp/getMtSuperValue/{sid} POST 请求
            baseURL: 'https://agent.juzicps.com/',
            method: 'post',
            url: `agent/mp/getMtSuperValue/${sid}`,
            timeout: 10000,
            withCredentials: false,
          }).then(response => {
            let res = response.data;
            if (res.code === 200) {
              this.items = res.data;
            }
          }).catch(error => {
            console.log(error.response.data);
          });
        },
      }
    });
  </script>
</body>
</html>
